/**
 * 开发环境的配置内容
 */
const MysqlSession = require('koa-mysql-session');
const data = new (require('../data')).data();

let store = new MysqlSession({
    user: 'root',
    password: 'Yiteng2018',
    database: 'yixin_zh',
    host: '47.75.76.213'
});

let cookie = {
    maxAge: '', // cookie有效时长
    expires: '',  // cookie失效时间
    path: '', // 写cookie所在的路径
    domain: '', // 写cookie所在的域名
    httpOnly: '', // 是否只用于http请求中获取
    overwrite: '',  // 是否允许重写
    secure: '',
    sameSite: '',
    signed: ''
};

// 数据库动态配置
var dynamic = (async () => {
    var dynamicObj = {};
    var sql = 'select `key`,`value` from config';
    var res = await data.query(sql);
    for (var i = 0; i < res.length; i++) {
        eval('dynamicObj.' + res[i].key + '=res[i].value;');
    }
    return await dynamicObj;
})();

module.exports = {
    dynamic: dynamic,
    env: 'development', // 环境名称
    port: 8084,         // 服务端口号
    registerToken: 'guolingfeng',
    store: store,
    cookie: cookie,
    wx: {
        getAccessToken: 'https://api.weixin.qq.com/sns/oauth2/access_token?grant_type=authorization_code',
        getRefresh_token: 'https://api.weixin.qq.com/sns/oauth2/refresh_token?grant_type=refresh_token',
        getUserInfo: 'https://api.weixin.qq.com/sns/userinfo?'
    },
    Jsms: {
        smsSend: 'https://api.sms.jpush.cn/v1/codes',
        verification: 'https://api.sms.jpush.cn/v1/codes/{msg_id}/valid'
    },
    appstore: {
        testVerifyReceipt: 'https://sandbox.itunes.apple.com/verifyReceipt',
        formalVerifyReceipt: 'https://buy.itunes.apple.com/verifyReceipt'
    },
    noAuth: [
        'GET/dist',
        'GET/',
        'GET/game',
        'POST/game',
        'POST/register',
        'POST/login',
        'GET/login',
        'GET/error',
        'GET/frontEndConfig'
    ],  // 忽略权限的路由
    serverStatusInfo: {

        // 后台错误
        unknownError: { statusCode: 88, errinfo: '发生未知的错误' },
        NoLogin: { statusCode: 100, errinfo: 'no login' },
        AuthError: { statusCode: 101, errinfo: '授权失败' },
        NoAuth: { statusCode: 200, errinfo: 'no auth' },
        parameterError: { statusCode: 300, errinfo: '传入参数错误' },
        invalidID: { statusCode: 301, errinfo: '无效的ID' },
        invalidTask: { statusCode: 400, errinfo: '无效的任务' },
        unableTask: { statusCode: 401, errinfo: '无法完成该任务' },
        playerError: { statusCode: 500, errinfo: '玩家信息错误' },
        palyerNoFind: { statusCode: 501, errinfo: '找不到该玩家' },
        sqlNofind: { statusCode: 502, errinfo: '找不到该记录' },
        systemConfigError: { statusCode: 503, errinfo: '系统配置错误' },
        httpConnError: { state: 600, errinfo: '服务器http请求错误' },

        // 客户端错误
        wechatOpenidNoFind: { statusCode: 1000, errinfo: '找不到微信openid' },
        tokenError: { statusCode: 2000, errinfo: 'token过期' },
        resourcesMiss: { statusCode: 3000, errinfo: '资源不足' },
        friendIsAdd: { statusCode: 4000, errinfo: '好友已经关注' },
        rewardsReceived: { statusCode: 5000, errinfo: '奖励已领取过' },
        toDayRewardSuccess: { statusCode: 6000, errinfo: '今日奖励已领完' },
        resurrectionExhausted: { statusCode: 7000, errinfo: '复活次数耗尽' },
        activityError: { statusCode: 8000, errinfo: '活动未开启' },
        vcodeError: { statusCode: 9000, errinfo: '验证码错误' },
        gameOrderError: { statusCode: 9100, errinfo: '找不到该消费项目' },
        unknownPlatform: { statusCode: 9101, errinfo: '未知的平台' },
        receiptInvalid: { statusCode: 9102, errinfo: '凭证无效' }

    },
    authRole: [
        3, 4, 5
        // 高中低权限的角色ID
    ],
    game: {
        xitieshiTime: 20,
        doubleScoreTime: 20,
        // 任务规则
        task: {
            reset: [
                // 重置规则
                '每日任务（每天零点重置）',
                '每周任务（每周一零点重置）',
                '每月任务（每月一号零点重置）',
                '特殊任务'
            ],
            condition: [
                // 条件规则
                '完成比赛',
                '贪吃蛇长度',
                '吞噬玩家',
                '任意模式排名'
                /*
                "当日消耗金币",
                "当日消耗钻石",
                */
            ],
            /*
            classifier: [
                "场","米","名","名"
            ]
            */
            explain: [
                '完成比赛{0}场',
                '贪吃蛇超过长度{0}米',
                '吞噬玩家{0}名',
                '任意模式排名获得前{0}名'
            ]
        },
        sign: [
            ['exp', '经验'],
            ['golds', '金币'],
            ['diamonds', '钻石'],
            ['1001', '吸铁石']
        ],
        skin: {
            currency: [
                '金币',
                '钻石'
            ]
        },
        order: {
            state: [
                '等待发货', '已发货', '已确认收货'
            ]
        },
        gameOrder: {
            platform: [
                // appstore
                [
                    [6, { 'diamonds': 60 }],
                    [30, { 'diamonds': 300 }],
                    [68, { 'diamonds': 680 }],
                    [128, { 'diamonds': 1280 }],
                    [328, { 'diamonds': 3280 }]
                ]
            ]
        }
    }
};
// ["每日任务（每天零点重置）","每周任务（每周一零点重置）","每月任务（每月一号零点重置）"]
// ["",""]
